package model;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

import model.NodeElement;

public class MyJTreeRenderer extends DefaultTreeCellRenderer {

	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
													boolean leaf, int row, boolean hasFocus) {

		super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
		DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
		NodeElement nodeInfo = (NodeElement)(node.getUserObject());
		if (isPersonne(nodeInfo)) {
//			ImageIcon img = new ImageIcon(this.getClass().getResource("img/personne.png"));
			ImageIcon img = new ImageIcon(getClass().getResource("/images/personne2.png"));
			setIcon(img);
			setToolTipText(nodeInfo.getDescription());
		} else if (isApplication(nodeInfo)) {
			ImageIcon img = new ImageIcon(getClass().getResource("/images/tortue2.png"));
			setIcon(img);
			setToolTipText(nodeInfo.getDescription());
		}else if (isApplicationPrive(nodeInfo)) {
			ImageIcon img = new ImageIcon(getClass().getResource("/images/tortueCadena.png"));
			setIcon(img);
			setToolTipText(nodeInfo.getDescription());
		}
//		
//		else if (isGroupe(nodeInfo)) {
//			ImageIcon img = new ImageIcon(getClass().getResource("/images/comm.png"));
//			setIcon(img);
//			setToolTipText(nodeInfo.getDescription());
	//	}
		else if (isDossier(nodeInfo)) {
			ImageIcon img = new ImageIcon(getClass().getResource("/images/dossier.png"));
			setIcon(img);
			setToolTipText(nodeInfo.getDescription());
		}
		return this;
	}

	protected boolean isPersonne(NodeElement nodeInfo) {
		String type = nodeInfo.getType();
		if (type.equals(NodeElement.PERSON)) {
			return true;
		} 
		return false;
	}
	
	protected boolean isApplication(NodeElement nodeInfo) {
		String type = nodeInfo.getType();
		if (type.equals(NodeElement.APPLICATION)) {
			return true;
		} 
		return false;
	}
	
	protected boolean isApplicationPrive(NodeElement nodeInfo) {
		String type = nodeInfo.getType();
		if (type.equals(NodeElement.PRIVATEAPPLICATION)) {
			return true;
		} 
		return false;
	}
	
	protected boolean isGroupe(NodeElement nodeInfo) {
		String type = nodeInfo.getType();
		if (type.equals(NodeElement.GROUP)) {
			return true;
		} 
		return false;
	}
	
	protected boolean isDossier(NodeElement nodeInfo) {
		String type = nodeInfo.getType();
		if (type.equals(NodeElement.FOLDER)) {
			return true;
		} 
		return false;
	}
}